//
//  BaseSettingController.m
//  SinaWeibo
//
//  Created by Apple on 16/8/22.
//  Copyright © 2016年 Apple. All rights reserved.
//

#import "BaseSettingController.h"

#import "GroupModel.h"
#import "ItemSwitchModel.h"
#import "ItemArrowModel.h"
#import "SettingViewController.h"
#import "SettingCell.h"
#import "pictureQualitiController.h"
#import "ItemLogoutModel.h"
#import "ItemPictureQualityModel.h"

@interface BaseSettingController ()

@end

@implementation BaseSettingController

-(void)viewDidLoad{
    
    [super viewDidLoad];
    
    //设置Cell之间的间距
    self.tableView.tableHeaderView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, 0.5)];
    self.tableView.sectionFooterHeight = 0;
    self.tableView.sectionHeaderHeight = 15;

    
}


/**
 *  重写init方法设置为分组模式
 */
-(instancetype)initWithStyle:(UITableViewStyle)style{
    
    return [super initWithStyle:UITableViewStyleGrouped];
    
}

-(NSArray *)dataArray{
    
    if (!_dataArray) {
        _dataArray = [self setData];
    }
    return _dataArray;
}

/**
 *  setData方法返回nil，让子类重写返回数据
 */
-(NSArray *)setData{
    
    return nil;
    
}

#pragma mark - Table view data source

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    
    return self.dataArray.count;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    
    GroupModel *group = self.dataArray[section];
    
    return group.items.count;
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    NSString *identifier = @"settingCell";
    
    SettingCell *cell = [tableView dequeueReusableCellWithIdentifier:identifier];
    
    if (cell == nil) {
        cell = [[SettingCell alloc]initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:identifier];
    }
    
    GroupModel *group = self.dataArray[indexPath.section];
    
    ItemModel *item = group.items[indexPath.row];
    
    cell.item = item;
    
    return cell;
    
}


@end
